﻿using Castle.Core.Logging;
using NLog;
using System;

namespace Basefr.Logging.NLogExtensions
{
    public class NLogLoggerFactory : AbstractExtendedLoggerFactory
    {
        private const string DefaultConfigFileName = "NLog.config";

        public NLogLoggerFactory() : this(DefaultConfigFileName)
        {
        }

        public NLogLoggerFactory(string configFileName)
        {
            LogManager.LoadConfiguration(configFileName);
        }

        public override IExtendedLogger Create(string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException(nameof(name), "Logger Name Is Null Or Empty.");
            }

            return new NLogLogger(LogManager.GetLogger(name));
        }

        public override IExtendedLogger Create(string name, LoggerLevel level)
        {
            throw new NotSupportedException("Logger levels cannot be set at runtime. Please review your configuration file.");
        }
    }
}
